package 力扣._155_最小栈;

import java.util.Stack;

public class MinStack {
    private Stack<Integer> stack;
    private Stack<Integer> min_stack;   //存储当前长度栈的最小元素

    public MinStack() {
        stack = new Stack<>();
        min_stack = new Stack<>();

    }

    public void push(int val) {
        if (stack.isEmpty())
            min_stack.push(val);
        else
            min_stack.push(Math.min(min_stack.peek(), val));

        stack.push(val);
    }

    public void pop() {
        if (stack.isEmpty())
            return;
        stack.pop();
        min_stack.pop();

    }

    public int top() {
        if (stack.isEmpty())
            return -1;
        return stack.peek();
    }

    public int getMin() {
        return min_stack.peek();
    }
}
